package com.linhun.nickmao.demo.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

/**
 * 所有Activity的基类
 * Created by 冒秉文 on 2015/4/6.
 */
public abstract class BaseActivity extends ActionBarActivity {

    private ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        actionBar = getSupportActionBar();
        if(actionBar != null){
            configurationActionBar(actionBar);
        }
    }

    /**
     * 配置ActionBar 根据实际情况进行重写
     * @param bar
     */
    protected void configurationActionBar(ActionBar bar){
    }

    /**
     * 打开新的Activity
     * @param intent 打开Activity意图
     */
     protected void startNewActivity(Intent intent){
         startActivity(intent);
     }

    /**
     * 打开新的Activity
     * @param cls Activity 类对象
     * @param extra 传递的参数 不需要传递时穿null
     */
     protected  void startNewActivity(Class cls,Bundle extra){
         Intent intent = new Intent(this,cls);
         if(extra != null){
            intent.putExtras(extra);
         }
         startNewActivity(intent);
     }

    /**
     * 打开Activity并接收返回结果
     * @param intent
     * @param requestCode
     */
    protected  void startNewActivityForResult(Intent intent,int requestCode){
        startActivityForResult(intent,requestCode);
    }

    /**
     * 打开Activity并接收返回结果
     * @param cls
     * @param requestCode
     * @param extra
     */
    protected void startNewActivityForResult(Class cls,int requestCode,Bundle extra){
        Intent intent = new Intent(this,cls);
        if(extra != null){
            intent.putExtras(extra);
        }
        startNewActivityForResult(intent,requestCode);
    }



}
